<template>
	<view class="container" v-show="tokenShow">
		<order-receive v-if="userType==0" :isShowStaff="isShowStaff"></order-receive>
		<boss-public v-if="userType==1" :isShowBoss="isShowBoss"></boss-public>
	</view>
</template>

<script>
	import bossPublic from './boss-public.vue'
	import orderReceive from './order-receive.vue'
	export default {
		components: {
			bossPublic,
			orderReceive
		},
		data() {
			return {
				userType: 1,//用户类型0 雇员，1雇主
				userInfo: { user: {}, params: {} },//当前用户信息
				userJobStatus: '',//用户工作状态
				isShowBoss: 0,
				isShowStaff: 0,
				tokenShow:uni.getStorageSync('token')
			}
		},
		methods: {
			// 获取当前用户信息
			async getUserInfo () {
				let res = await this.$fetch(this.$api.get_current_user, {}, 'GET')
				if (res.code == 401){
					uni.reLaunch({ url: '/pages/login/login' })
					return
				}
				// if (res.code) return uni.showToast({ title: res.msg, icon: 'none' })
				if (res.code===531) {
					uni.navigateTo({
						url: '/pages/riskControl/riskControl',
					})
					return
				}
				if(res.data.payPwdFlag){
					uni.setStorageSync('isHavePayPassword',true)
				}
				else{
					uni.setStorageSync('isHavePayPassword',false)
				}
				uni.setStorageSync('userInfo', res.data)
				uni.setStorageSync('userType', res.data.userType)
				this.userInfo = res.data
				this.userType = uni.getStorageSync('userType')
				 uni.setStorageSync("level",res.data.user.level)//用户等级
				this.userJobStatus = this.userInfo.userJobStatus
				// console.log('用户工作',this.userInfo.idCardStatus,this.userInfo.user.authSwitch)
				++this.isShowStaff
				++this.isShowBoss
			},
		},
		
		onLoad() {
			if(!uni.getStorageSync('token')) {
				uni.reLaunch({ url: '/pages/login/login' }) 
			}
		},
		onShow() {
			uni.hideTabBar()
			this.userType = uni.getStorageSync('userType')
			this.getUserInfo()
			
		},
	}
</script>

<style scoped lang="less">
	.container {
		background: #FFFFFF;
	}
</style>
